using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FolderComparer
{
	public partial class PathPicker : UserControl
	{
		public PathPicker()
		{
			InitializeComponent();
		}

		private bool mPathMustExist = true;
		public bool PathMustExist
		{
			get
			{
				return mPathMustExist;
			}
			set
			{
				mPathMustExist = value;
			}
		}

		public string Path
		{
			get
			{
				if (PathMustExist && !Directory.Exists(this.TextPath.Text))
				{
					return "";
				}
				return this.TextPath.Text;
			}
			set
			{
				if (PathMustExist && !Directory.Exists(value))
				{
					return;
				}
				this.TextPath.Text = value;
			}
		}

		public bool PathExists
		{
			get
			{
				return Directory.Exists(Path);
			}
		}

		private void ButtonBrowse_Click(object sender, EventArgs e)
		{
			FolderBrowserDialog f = new FolderBrowserDialog();
			if (PathExists)
			{
				f.SelectedPath = Path;
			}
			f.ShowNewFolderButton = true;
			f.Description = "Please select a folder:";
			DialogResult result = f.ShowDialog();
			if (result == DialogResult.OK)
			{
				Path = f.SelectedPath;
			}
		}
	}
}
